<template>
  <el-dialog v-model="dialogPromoteVisible" title="赋权操作" center width="30%">
    <!-- Radio 单选框 -->
		<el-radio-group v-model="radio" class="ml-4">
			<el-radio label="产品管理员" size="large" value="产品管理员">产品管理员</el-radio>
			<el-radio label="用户管理员" size="large" value="用户管理员">用户管理员</el-radio>
			<el-radio label="消息管理员" size="large" value="消息管理员">消息管理员</el-radio>
		</el-radio-group>
		<template #footer>
			<span class="dialog-footer">
				<el-button type="primary" @click="promote">确定</el-button>
			</span>
		</template>
	</el-dialog>
</template>
 
<script setup lang="ts">
  import { ref, onBeforeUnmount, reactive } from 'vue';
  import { ElMessage } from 'element-plus';
  import { bus } from "@/utils/mitt.js";
  import { changeIdentityToAdmin } from '@/api/userinfor.js';
  
  const radio = ref()
  const userid = ref()
	bus.on('promoteId', (id : number) => {
		userid.value = id
	})

  // id identity 赋权
  const promote = async () => {
    const res = await changeIdentityToAdmin(userid.value, radio.value)
    if (res.data.status == 0) {
			ElMessage({
				message: '赋权管理员成功',
				type: 'success',
			})
			bus.emit('offDialog',1)  // if(1)关闭弹窗  
			dialogPromoteVisible.value = false
		} else {
			ElMessage.error('赋权管理员失败')
			dialogPromoteVisible.value = false
		}
  }

  // ------------------------------------------------------------------------------
  // 弹窗开关
	const dialogPromoteVisible = ref(false) 
  const open = () => {
    dialogPromoteVisible.value = true
  }
  defineExpose({
    open
  })
  onBeforeUnmount(()=>{
    bus.all.clear()
  })
</script>
 
<style lang="scss" scoped>
	.el-radio-group {
		display: flex;
		justify-content: center;
	}
</style>
